package com.num2.service.lhr;

import java.util.List;

import javax.annotation.Resource;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.stereotype.Service;
import com.num2.dao.lhr.inter.IOpenAccDao;
import com.num2.form.lhr.NextPage;
import com.num2.form.lhr.OpenMoneyForm;
import com.num2.form.lhr.UserForm;
import com.num2.model.lhr.allSelModel;

@Service
public class OpenAccService {
	@Resource
	private SqlSessionFactory sqlSessionFactory;
	/*@Resource
	private NextPage np;*/
;
	//开户方法
	public boolean openAcc(UserForm uf){
		//打开session
        SqlSession sqlSession = sqlSessionFactory.openSession();
        //通过 注解 获取 接口实现类的对象
        IOpenAccDao accdao = sqlSession.getMapper(IOpenAccDao.class);
        //添加账户方法
        boolean result=accdao.openacc(uf);
		//关闭会话
        sqlSession.close();
        //获取返回结果 返回
		return result;
	}
	//查询用户账户
	public boolean openSelec(String usename){
		SqlSession sqlSession = sqlSessionFactory.openSession();
		IOpenAccDao accdao = sqlSession.getMapper(IOpenAccDao.class);
		List<String> openSlectResutlt = accdao.openSel(usename);
		if(openSlectResutlt.size()>0&&openSlectResutlt!=null){
			sqlSession.close();
		return false;
		}else{
			sqlSession.close();
			return true;
		}
	}
	//查询用户ID
	public int openuseidSel(String usenum){
		SqlSession sqlSession = sqlSessionFactory.openSession();
		IOpenAccDao accdao = sqlSession.getMapper(IOpenAccDao.class);
		int selectuseid=accdao.openuseid(usenum);
		sqlSession.close();
		return selectuseid;
	}
	//添加注册存入资金
	public boolean deposOpenMoney(OpenMoneyForm omf){
		SqlSession sqlSession = sqlSessionFactory.openSession();
		IOpenAccDao accdao = sqlSession.getMapper(IOpenAccDao.class);
		if(accdao.openDepoInsert(omf)){
			sqlSession.close();
			return true;
		}else{
			sqlSession.close();
			return false;
		}
	}
	
	//查询全部用户信息
	public NextPage allSelectServ(int currentPage){
		SqlSession sqlSession = sqlSessionFactory.openSession();
		IOpenAccDao accdao = sqlSession.getMapper(IOpenAccDao.class);
		NextPage np=new NextPage();
		np.setCurrentPage(currentPage);
		//查询全部
		List<allSelModel> results=accdao.all();
		int max=results.size();
		//查询前10条显示的内容
		List<allSelModel> result = accdao.allSelect(np);
		np.setNumPage(max);
		np.setResPage(result);
		return np;
	}
	//查询启用用户
	public NextPage enableSelectServ(int currentPage){
		SqlSession sqlSession = sqlSessionFactory.openSession();
		IOpenAccDao accdao = sqlSession.getMapper(IOpenAccDao.class);
		NextPage np=new NextPage();
		np.setCurrentPage(currentPage);
		List<allSelModel> results=accdao.allEnable();
		int max=results.size();
		List<allSelModel> result = accdao.enableSelect(np);
		np.setNumPage(max);
		np.setResPage(result);
		return np;
	}
	//查询冻结用户
	public NextPage frozeSelectServ(int currentPage){
		SqlSession sqlSession = sqlSessionFactory.openSession();
		IOpenAccDao accdao = sqlSession.getMapper(IOpenAccDao.class);
		NextPage np=new NextPage();
		np.setCurrentPage(currentPage);
		List<allSelModel> results=accdao.allForzen();
		int max=results.size();
		List<allSelModel> result = accdao.forzenSelect(np);
		np.setNumPage(max);
		np.setResPage(result);
		return np;
	}
	
	//将冻结用户启用
	public boolean openAccSel(String usernum){
		SqlSession sqlSession = sqlSessionFactory.openSession();
		IOpenAccDao accdao = sqlSession.getMapper(IOpenAccDao.class);
		return accdao.openAccDao(usernum);
	}
	//将启用用户冻结
	public boolean closeAccSel(String usernum){
		SqlSession sqlSession = sqlSessionFactory.openSession();
		IOpenAccDao accdao = sqlSession.getMapper(IOpenAccDao.class);
		return accdao.closeAccDao(usernum);
	}
	
	public NextPage condition(int currentPage,String query){
		SqlSession sqlSession = sqlSessionFactory.openSession();
		IOpenAccDao accdao = sqlSession.getMapper(IOpenAccDao.class);
		NextPage np=new NextPage();
		np.setCurrentPage(currentPage);
		np.setQuery(query);
		List<allSelModel> results=accdao.conditionQuerynum(query);
		int max=results.size();
		List<allSelModel> result = accdao.conditionQuery(np);
		np.setNumPage(max);
		np.setResPage(result);
		return np;
	}
	public SqlSessionFactory getSqlSessionFactory() {
		return sqlSessionFactory;
	}

	public void setSqlSessionFactory(SqlSessionFactory sqlSessionFactory) {
		this.sqlSessionFactory = sqlSessionFactory;
	}
	
}
